﻿namespace MonetDbDataProviderTest
{
    using MonetDbDataProvider;
    using MonetDbDataProvider.Mapi;

    using NUnit.Framework;

    [TestFixture]
    public class MonetDbErrorHandlingTest : BaseTest
    {
        [Test]
        public void InsertIntoNonExistentTableTest()
        {
            // Arrange
            using (var cmd = new MonetDbCommand(base.MonetDbConn))
            {
                cmd.Connection.Open();
                cmd.CommandText = "INSERT INTO tabledoesnotexist(colname) VALUES ('test');";

                // Act & Assert
                Assert.Throws<MonetDbException>(() => cmd.ExecuteNonQuery());

                cmd.Connection.Close();
            }
        }

        [Test]
        public void InsertWithoutOpenConnectionTest()
        {
            // Arrange
            using (var cmd = new MonetDbCommand(base.MonetDbConn))
            {
                // cmd.Connection.Open(); Connection not opened.
                cmd.CommandText = "INSERT INTO tabledoesnotexist(colname) VALUES ('test');";

                // Act & Assert
                Assert.Throws<MonetDbProviderException>(() => cmd.ExecuteNonQuery());
            }
        }
    }
}
